package com.homeproject.trailservice.dal;

import com.homeproject.trailservice.domain.Customer;
import com.homeproject.trailservice.domain.DeliveryCompany;
import com.homeproject.trailservice.domain.relationship.Submit;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Within a community group purchase, there are following entities and relationships
 *
 * Customer - submit -> SubOrder
 * GroupManager - Initiate -> Order
 * Fruit - PartOf -> SubOrder
 * Vegetable - PartOf -> SubOrder
 * SubOrder -> ChildOf -> Order
 * Provider - Prepare -> Order
 * Deliverer - Deliver -> Order
 * Deliverer - WorksFor -> DeliveryCompany
 * */
@Component
public interface CustomerRepository extends Neo4jRepository<Customer,Long> {

    @Query("match (customer:Customer{name:$customerName}) " +
            "create (subOrder:SubOrder{price:$price}) " +
            "create (customer)-[submit:Submit]->(subOrder) " +
            "return submit")
    public List<Object> submitOrder(@Param("customerName") String customerName, @Param("price")long price
                            );

}
